

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.model_base &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.model_base</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.model_base</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">federatedml.util.param_extract</span> <span class="k">import</span> <span class="n">ParamExtract</span>
<span class="kn">from</span> <span class="nn">arch.api.utils</span> <span class="k">import</span> <span class="n">log_utils</span>

<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">log_utils</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span>


<div class="viewcode-block" id="ModelBase"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase">[docs]</a><span class="k">class</span> <span class="nc">ModelBase</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model_output</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model_param</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transfer_variable</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flowid</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">taskid</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_run</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tracker</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cv_fold</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">def</span> <span class="nf">_init_runtime_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">component_parameters</span><span class="p">):</span>
        <span class="n">param_extracter</span> <span class="o">=</span> <span class="n">ParamExtract</span><span class="p">()</span>
        <span class="n">param</span> <span class="o">=</span> <span class="n">param_extracter</span><span class="o">.</span><span class="n">parse_param_from_config</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model_param</span><span class="p">,</span> <span class="n">component_parameters</span><span class="p">)</span>
        <span class="n">param</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_init_model</span><span class="p">(</span><span class="n">param</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">need_cv</span> <span class="o">=</span> <span class="n">param</span><span class="o">.</span><span class="n">cv_param</span><span class="o">.</span><span class="n">need_cv</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="n">need_cv</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span> <span class="o">=</span> <span class="n">need_cv</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">need_run</span> <span class="o">=</span> <span class="n">param</span><span class="o">.</span><span class="n">need_run</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="n">need_run</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_run</span> <span class="o">=</span> <span class="n">need_run</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;need_run: </span><span class="si">{}</span><span class="s2">, need_cv: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">need_run</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">need_cv</span>

    <span class="k">def</span> <span class="nf">_init_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_load_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_dict</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_parse_need_run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_dict</span><span class="p">,</span> <span class="n">model_meta_name</span><span class="p">):</span>
        <span class="n">meta_obj</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">model_dict</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;model&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">model_meta_name</span><span class="p">)</span>
        <span class="n">need_run</span> <span class="o">=</span> <span class="n">meta_obj</span><span class="o">.</span><span class="n">need_run</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_run</span> <span class="o">=</span> <span class="n">need_run</span>

    <span class="k">def</span> <span class="nf">_run_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_sets</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stage</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">train_data</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">eval_data</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">data</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">for</span> <span class="n">data_key</span> <span class="ow">in</span> <span class="n">data_sets</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;train_data&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">train_data</span> <span class="o">=</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">][</span><span class="s2">&quot;train_data&quot;</span><span class="p">]</span>

            <span class="k">if</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;eval_data&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">eval_data</span> <span class="o">=</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">][</span><span class="s2">&quot;eval_data&quot;</span><span class="p">]</span>

            <span class="k">if</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;data&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">data_sets</span><span class="p">[</span><span class="n">data_key</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">stage</span> <span class="o">==</span> <span class="s1">&#39;cross_validation&#39;</span><span class="p">:</span>
            <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Need cross validation.&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cross_validation</span><span class="p">(</span><span class="n">train_data</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">train_data</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="s1">&#39;train&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">train_data</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="s1">&#39;predict&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">train_data</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="k">lambda</span> <span class="n">value</span><span class="p">:</span> <span class="n">value</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;train&quot;</span><span class="p">])</span>

            <span class="k">if</span> <span class="n">eval_data</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="s1">&#39;validate&#39;</span><span class="p">)</span>
                <span class="n">eval_data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">eval_data</span><span class="p">)</span>

                <span class="k">if</span> <span class="n">eval_data_output</span><span class="p">:</span>
                    <span class="n">eval_data_output</span> <span class="o">=</span> <span class="n">eval_data_output</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="k">lambda</span> <span class="n">value</span><span class="p">:</span> <span class="n">value</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;validation&quot;</span><span class="p">])</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="ow">and</span> <span class="n">eval_data_output</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="n">eval_data_output</span><span class="p">)</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="ow">and</span> <span class="n">eval_data_output</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="n">eval_data_output</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">set_predict_data_schema</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="p">,</span> <span class="n">train_data</span><span class="o">.</span><span class="n">schema</span><span class="p">)</span>
        
        <span class="k">elif</span> <span class="n">eval_data</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">eval_data</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="k">lambda</span> <span class="n">value</span><span class="p">:</span> <span class="n">value</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;test&quot;</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">set_predict_data_schema</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="p">,</span> <span class="n">eval_data</span><span class="o">.</span><span class="n">schema</span><span class="p">)</span>
        
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">stage</span> <span class="o">==</span> <span class="s2">&quot;fit&quot;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="p">:</span>
            <span class="c1"># LOGGER.debug(&quot;data is {}&quot;.format(self.data_output.first()[1].features))</span>

            <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;In model base, data_output schema: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="o">.</span><span class="n">schema</span><span class="p">))</span>

<div class="viewcode-block" id="ModelBase.run"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.run">[docs]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">component_parameters</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">need_cv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_init_runtime_parameters</span><span class="p">(</span><span class="n">component_parameters</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">need_cv</span><span class="p">:</span>
            <span class="n">stage</span> <span class="o">=</span> <span class="s1">&#39;cross_validation&#39;</span>
        <span class="k">elif</span> <span class="s2">&quot;model&quot;</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_load_model</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
            <span class="n">stage</span> <span class="o">=</span> <span class="s2">&quot;transform&quot;</span>
        <span class="k">elif</span> <span class="s2">&quot;isometric_model&quot;</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_load_model</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
            <span class="n">stage</span> <span class="o">=</span> <span class="s2">&quot;fit&quot;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">stage</span> <span class="o">=</span> <span class="s2">&quot;fit&quot;</span>

        <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;data&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_run_data</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">],</span> <span class="n">stage</span><span class="p">)</span></div>

<div class="viewcode-block" id="ModelBase.predict"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">):</span>
        <span class="k">pass</span></div>

<div class="viewcode-block" id="ModelBase.fit"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.fit">[docs]</a>    <span class="k">def</span> <span class="nf">fit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">):</span>
        <span class="k">pass</span></div>

<div class="viewcode-block" id="ModelBase.transform"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.transform">[docs]</a>    <span class="k">def</span> <span class="nf">transform</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">):</span>
        <span class="k">pass</span></div>

<div class="viewcode-block" id="ModelBase.cross_validation"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.cross_validation">[docs]</a>    <span class="k">def</span> <span class="nf">cross_validation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">):</span>
        <span class="k">pass</span></div>

<div class="viewcode-block" id="ModelBase.save_data"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.save_data">[docs]</a>    <span class="k">def</span> <span class="nf">save_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;data output is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_output</span><span class="o">.</span><span class="n">collect</span><span class="p">())))</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_output</span></div>

<div class="viewcode-block" id="ModelBase.export_model"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.export_model">[docs]</a>    <span class="k">def</span> <span class="nf">export_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># self.model_output = {&quot;XXXMeta&quot;: &quot;model_meta&quot;,</span>
        <span class="c1">#                     &quot;XXXParam&quot;: &quot;model_param&quot;}</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">model_output</span></div>

<div class="viewcode-block" id="ModelBase.set_flowid"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_flowid">[docs]</a>    <span class="k">def</span> <span class="nf">set_flowid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flowid</span><span class="p">):</span>
        <span class="c1"># self.flowid = &#39;_&#39;.join(map(str, [self.flowid, flowid]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">flowid</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">taskid</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">flowid</span><span class="p">)])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_transfer_variable</span><span class="p">()</span></div>

<div class="viewcode-block" id="ModelBase.set_transfer_variable"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_transfer_variable">[docs]</a>    <span class="k">def</span> <span class="nf">set_transfer_variable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transfer_variable</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;set flowid to transfer_variable, flowid: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flowid</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">transfer_variable</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">flowid</span><span class="p">)</span></div>

<div class="viewcode-block" id="ModelBase.set_taskid"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_taskid">[docs]</a>    <span class="k">def</span> <span class="nf">set_taskid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">taskid</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">taskid</span> <span class="o">=</span> <span class="n">taskid</span></div>

<div class="viewcode-block" id="ModelBase.get_metric_name"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.get_metric_name">[docs]</a>    <span class="k">def</span> <span class="nf">get_metric_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name_prefix</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">name_prefix</span>

        <span class="k">return</span> <span class="s1">&#39;_&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="p">[</span><span class="n">name_prefix</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">flowid</span><span class="p">]))</span></div>

<div class="viewcode-block" id="ModelBase.set_tracker"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_tracker">[docs]</a>    <span class="k">def</span> <span class="nf">set_tracker</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tracker</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tracker</span> <span class="o">=</span> <span class="n">tracker</span></div>

<div class="viewcode-block" id="ModelBase.set_predict_data_schema"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_predict_data_schema">[docs]</a>    <span class="k">def</span> <span class="nf">set_predict_data_schema</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">predict_data</span><span class="p">,</span> <span class="n">schema</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">predict_data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">predict_data</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;header&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">,</span> <span class="s2">&quot;predict_result&quot;</span><span class="p">,</span> <span class="s2">&quot;predict_score&quot;</span><span class="p">,</span> <span class="s2">&quot;predict_detail&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">],</span>
                                   <span class="s2">&quot;sid_name&quot;</span><span class="p">:</span> <span class="n">schema</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;sid_name&#39;</span><span class="p">)}</span></div>

<div class="viewcode-block" id="ModelBase.callback_meta"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.callback_meta">[docs]</a>    <span class="k">def</span> <span class="nf">callback_meta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">metric_name</span><span class="p">,</span> <span class="n">metric_namespace</span><span class="p">,</span> <span class="n">metric_meta</span><span class="p">):</span>
        <span class="c1"># tracker = Tracking(&#39;123&#39;, &#39;abc&#39;)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span><span class="p">:</span>
            <span class="n">metric_name</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">metric_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cv_fold</span><span class="p">)])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tracker</span><span class="o">.</span><span class="n">set_metric_meta</span><span class="p">(</span><span class="n">metric_name</span><span class="o">=</span><span class="n">metric_name</span><span class="p">,</span>
                                     <span class="n">metric_namespace</span><span class="o">=</span><span class="n">metric_namespace</span><span class="p">,</span>
                                     <span class="n">metric_meta</span><span class="o">=</span><span class="n">metric_meta</span><span class="p">)</span></div>

<div class="viewcode-block" id="ModelBase.callback_metric"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.callback_metric">[docs]</a>    <span class="k">def</span> <span class="nf">callback_metric</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">metric_name</span><span class="p">,</span> <span class="n">metric_namespace</span><span class="p">,</span> <span class="n">metric_data</span><span class="p">):</span>
        <span class="c1"># tracker = Tracking(&#39;123&#39;, &#39;abc&#39;)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">need_cv</span><span class="p">:</span>
            <span class="n">metric_name</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">metric_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cv_fold</span><span class="p">)])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tracker</span><span class="o">.</span><span class="n">log_metric_data</span><span class="p">(</span><span class="n">metric_name</span><span class="o">=</span><span class="n">metric_name</span><span class="p">,</span>
                                     <span class="n">metric_namespace</span><span class="o">=</span><span class="n">metric_namespace</span><span class="p">,</span>
                                     <span class="n">metrics</span><span class="o">=</span><span class="n">metric_data</span><span class="p">)</span></div>

<div class="viewcode-block" id="ModelBase.set_cv_fold"><a class="viewcode-back" href="../../federatedml.html#federatedml.model_base.ModelBase.set_cv_fold">[docs]</a>    <span class="k">def</span> <span class="nf">set_cv_fold</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cv_fold</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cv_fold</span> <span class="o">=</span> <span class="n">cv_fold</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>